﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Telerik.Web.UI;
using KPIS.GERP.GIMS.DAL;
using KPIS.GERP.GIMS.MODEL;
using KPIS.GERP.GIMS.IBLL;
using KPIS.GERP.GIMS.BLL;

namespace KPIS.GERP.GIMS.APP.APP_UI.Form
{
    public partial class ICM_Receives : System.Web.UI.Page
    {
        Common.Main cn = new Common.Main();
        CommandControl cmdFac = new CommandControl();
        IBLLMasterPurchaseRule bll = new MasterPurchaseRuleBLL();
        IBLLSysYearType bllYearType = new SysYearTypeBLL();
        SysControlBLL bllSysCon = new SysControlBLL(); 
        D_ReceiveType d_receive_type = new D_ReceiveType();
        IBLLTree bllTree = new TreeBLL();

        ReceiveBLL recBLL = new ReceiveBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadYearType();
                LoadDefault();
                LoadGrid();                               
            }
        }
        protected void LoadDefault()
        {
            //SysControlInfo infoDefault = bllSysCon.GetDefaultData();
            //if (infoDefault.YearType != null)
            //{
            //    cbYearType.SelectedValue = infoDefault.YearType.ToString();
            //    Session["yearSeq"] = cbYearType.SelectedValue;
            //    Session["yearSeq_Urgent"] = cbYearType.SelectedValue;

            //}
            //if (infoDefault.Year != null)
            //{
            //    txtYear.Text = infoDefault.Year.ToString();
            //    Session["year"] = txtYear.Text;
            //    Session["year_Urgent"] = txtYear.Text;
            //}
        }
        protected void LoadYearType()
        {
            //IList<SysYearTypeInfo> infoList = bllYearType.GetSysYearType();
            //cbYearType.DataSource = infoList;
            //cbYearType.DataBind();
        }
        public void LoadReceiveType()
        {
            cbReceiveType.DataSource = d_receive_type.GetList();
            cbReceiveType.DataBind();
        }
        public void LoadDeliveryNote()
        {

        }

        public void GetKeyValue(string seq)
        {
            //if (seq.Length > 0)
            //{
            //    MasterPurchaseRuleInfo info = bll.GetMasterPurchaseRule(Convert.ToInt32(seq));

                //txtName.Text = info.Name;
                //txtDescr.Text = info.Descr;
                //LoadBgmSourceTreeWithRule(Convert.ToInt32(seq), false);

                //cmdFac.ViewCommand(panelList, panelGrid, panelCommand);
            //}
        }

        protected void AddNew_Click(object sender, EventArgs e)
        {
            LoadReceiveType();
            panelGrid.Visible = false;
            PanelAddData.Visible = true;
            //cmdFac.AddNewCommand(panelList, panelGrid, panelCommand);
            //LoadAllBgmSourceTree();
        }

        protected void Continue_Click(object sender, EventArgs e)
        {
            //cmdFac.AddNewCommand(Panel1, panelGrid, panelCommand);
            //LoadAllBgmSourceTree();
        }
        protected void Edit_Click(object sender, EventArgs e)
        {
            //cmdFac.EditCommand(panelList, panelGrid, panelCommand);
            //LoadBgmSourceTreeWithRule(Convert.ToInt32(hdSeq.Value), true);
        }

        protected void Delete_Click(object sender, EventArgs e)
        {
            
        }
        private void LoadGrid()
        {
            IList<M_IcmReceiveObject> info = recBLL.GetReceiveObject((int?)null);
            grdInventory.DataSource = info;
            grdInventory.DataBind();
        }
        protected void grdInventory_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            LoadGrid();
        }
        protected void grdInventory_ItemCommand(object sender, GridCommandEventArgs e)
        {
        }
        protected void AddNewSave_Click(object sender, EventArgs e)
        {
        
        }

        protected void Cancel_Click(object sender, EventArgs e)
        {
        //    cmdFac.CancelCommand(panelList, panelGrid, panelCommand);
        //    LoadBgmSourceTreeWithRule(Convert.ToInt32(hdSeq.Value), false);
        }

        protected void ShowGrid_Click(object sender, EventArgs e)
        {
            cmdFac.CancelCommand(panelGrid, panelGrid, panelCommand);
            LoadGrid();
        }      

        protected void RadManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
        {
            //GetKeyValue(e.Argument);
        }

        protected void OnAjaxRequest(object sender, AjaxRequestEventArgs e)
        {
            //RadAjaxPanel1.Controls.Add(Page.LoadControl("../UserControl/Personal_Data.ascx"));
        }

        protected void SourceTree_NodeDataBound(object sender, RadTreeNodeEventArgs e)
        {
            //e.Node.Checked = ((e.Node.DataItem as TreeInfo).Check == 1);
        }

        protected void clearFilter_Click(object sender, EventArgs e)
        {
            //foreach (GridColumn column in Grid.MasterTableView.Columns)
            //{
            //    column.CurrentFilterFunction = GridKnownFunction.NoFilter;
            //    column.CurrentFilterValue = string.Empty;
            //}
            //Grid.MasterTableView.FilterExpression = string.Empty;
            //LoadDataGrid();
        }

        protected void btnShow_Click(object sender, EventArgs e)
        {
            //Session["yearSeq"] = cbYearType.SelectedValue;
            //Session["year"] = txtYear.Text;
            LoadGrid();
        }
    }
}
